<template>
  <div id="my_input_container">
    <input ref="input" v-model="inputValue" :type="type" class="input" />
    <span class="title" :class="{ focus_title: inputValue }">{{ title }}</span>
    <div class="line"></div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

interface IProps {
  title: string;
  type?: string;
}
const props = withDefaults(defineProps<IProps>(), {
  type: 'text'
});

const inputValue = ref('');
const input = ref<HTMLInputElement>();
</script>

<style lang="less" scoped>
#my_input_container {
  display: flex;
  flex-direction: column;
  position: relative;
  height: fit-content;
  box-sizing: border-box;
  padding-top: 14px;
  width: 100%;
  .title {
    position: absolute;
    color: #eee;
    font-size: 18px;
    left: 0;
    bottom: 5px;
    transition: transform 0.3s ease, font-size 0.3s ease;
    will-change: transform, font-size;
    user-select: none;
    pointer-events: none;
  }
  .input {
    border: none;
    background-color: inherit;
    border-bottom: 1px #c0c0c0 solid;
    outline: none;
    padding: 10px 0 5px 0;
    font-size: 18px;
    color: black;
  }
  .input:focus + .title {
    transform: translateY(-30px);
    font-size: 14px;
    color: #2c6fdb;
  }
  .focus_title {
    transform: translateY(-30px);
    font-size: 14px;
    color: #2c6fdb;
  }
  .input:focus ~ .line {
    transform: scaleX(1);
    transform-origin: center;
  }
  .line {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 1px;
    width: 100%;
    transform: scaleX(0);
    transition: transform 0.3s linear;
    will-change: transform;
    background-color: #2c6fdb;
  }
}
</style>
